/* Theme state is applied by theme-toggle.js using localStorage key cpp-textbook-theme. */

:root,
html[data-theme="light"] {
  color-scheme: light;
  --page-bg: #f7fbfc;
  --surface-bg: #ffffff;
  --surface-alt: #edf7f8;
  --text: #17324d;
  --muted-text: #506577;
  --heading: #007f86;
  --accent: #b8dfe3;
  --accent-strong: #00a8b5;
  --border: #b8dfe3;
  --code-bg: #e8f7f9;
  --link: #006d75;
  --link-hover: #00838f;
  --shadow: rgba(0, 75, 82, 0.15);
  --table-row-alt: #f2f7f8;
  --table-hover: #e0f7f9;
  --menu-bg: #e0f7f9;
  --menu-active-bg: #006d75;
  --figure-bg: #afeeee;
  --figure-border: #ffe4e1;
  --figcaption-border: #b223e7;
  --note-bg: #e7f5fe;
  --warning-bg: #fff4df;
  --on-accent: #ffffff;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --page-bg: #101820;
    --surface-bg: #17232e;
    --surface-alt: #20313d;
    --text: #e6eef2;
    --muted-text: #a9bbc4;
    --heading: #62d6df;
    --accent: #31515a;
    --accent-strong: #2fb8c4;
    --border: #31515a;
    --code-bg: #0d2430;
    --link: #74dbe3;
    --link-hover: #9ff0f5;
    --shadow: rgba(0, 0, 0, 0.35);
    --table-row-alt: #1f303b;
    --table-hover: #263d49;
    --menu-bg: #173844;
    --menu-active-bg: #2fb8c4;
    --figure-bg: #173844;
    --figure-border: #31515a;
    --figcaption-border: #2fb8c4;
    --note-bg: #123044;
    --warning-bg: #3a2b15;
    --on-accent: #ffffff;
  }
}

html[data-theme="dark"] {
  color-scheme: dark;
  --page-bg: #101820;
  --surface-bg: #17232e;
  --surface-alt: #20313d;
  --text: #e6eef2;
  --muted-text: #a9bbc4;
  --heading: #62d6df;
  --accent: #31515a;
  --accent-strong: #2fb8c4;
  --border: #31515a;
  --code-bg: #0d2430;
  --link: #74dbe3;
  --link-hover: #9ff0f5;
  --shadow: rgba(0, 0, 0, 0.35);
  --table-row-alt: #1f303b;
  --table-hover: #263d49;
  --menu-bg: #173844;
  --menu-active-bg: #2fb8c4;
  --figure-bg: #173844;
  --figure-border: #31515a;
  --figcaption-border: #2fb8c4;
  --note-bg: #123044;
  --warning-bg: #3a2b15;
  --on-accent: #ffffff;
}

body {
  background-color: var(--page-bg);
  color: var(--text);
  font-family: Arial, sans-serif;
  line-height: 1.6;
  padding: 20px;
  max-width: 900px;
  margin: 0 auto;
}

h1,
h2,
h3 {
  color: var(--heading);
  border-bottom: 2px solid var(--accent-strong);
  padding-bottom: 5px;
}

ul {
  list-style-type: none;
}

ul li {
  position: relative;
  padding-left: 25px;
  margin-bottom: 8px;
}

ul li::before {
  content: "\25AA";
  position: absolute;
  left: 0;
  color: var(--accent-strong);
  font-size: 1.2em;
}

ol {
  list-style-type: none;
  counter-reset: custom-counter;
}

ol li {
  counter-increment: custom-counter;
  position: relative;
  padding-left: 35px;
  margin-bottom: 8px;
}

ol li::before {
  content: counter(custom-counter);
  position: absolute;
  left: 0;
  top: 0;
  background: var(--accent-strong);
  color: var(--on-accent);
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9em;
}

ul:not(ol ul) {
  list-style-type: none;
}

ul:not(ol ul) li::before {
  content: "\25AA";
}

ol ul {
  list-style-type: disc;
  padding-left: 40px;
}

ol ul li::before {
  content: none;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin: 15px 0;
  background: var(--surface-bg);
  color: var(--text);
  box-shadow: 0 2px 4px var(--shadow);
}

th,
td {
  padding: 10px;
  border: 1px solid var(--border);
  text-align: left;
}

th {
  background-color: var(--accent-strong);
  color: var(--on-accent);
}

tr:nth-child(even) {
  background-color: var(--table-row-alt);
}

tr:hover {
  background-color: var(--table-hover);
}

h1 {
  font-size: 2rem;
}

h2 {
  font-size: 1.7rem;
}

h3 {
  font-size: 1.4rem;
}

h4 {
  color: var(--heading);
  font-size: 1.2rem;
  text-align: center;
}

a {
  color: var(--link);
  text-decoration: none;
  transition: all 0.3s ease;
}

a:hover {
  color: var(--link-hover);
  text-decoration: underline;
}

a.menu {
  display: inline-block;
  padding: 8px 16px;
  margin: 4px 0;
  background: var(--menu-bg);
  border-radius: 20px;
  transition: all 0.3s ease;
}

a.menu:active {
  background: var(--menu-active-bg);
  color: var(--on-accent);
  text-decoration: none;
}

a.menu:hover {
  background: var(--accent-strong);
  color: var(--on-accent);
}

img {
  max-width: 80%;
  border-radius: 12px;
  border: 4px solid var(--border);
  background: var(--surface-bg);
  padding: 8px;
  box-shadow: 0 4px 12px var(--shadow);
  transition: transform 0.3s ease;
}

img:hover {
  transform: scale(1.02);
}

pre,
code {
  background: var(--code-bg);
  color: var(--text);
  border-radius: 6px;
  font-family: "Courier New", monospace;
}

pre {
  padding: 16px;
  overflow-x: auto;
  border-left: 4px solid var(--accent-strong);
}

.example,
.note {
  background: var(--note-bg);
  padding: 16px;
  border-radius: 8px;
  border-left: 5px solid var(--accent-strong);
  margin: 20px 0;
}

.warning {
  background: var(--warning-bg);
  padding: 16px;
  border-radius: 8px;
  border-left: 5px solid var(--accent-strong);
  margin: 20px 0;
}

hr {
  border: none;
  height: 2px;
  background: linear-gradient(to right, transparent, var(--accent-strong), transparent);
  margin: 2rem 0;
}

figure {
  float: none;
  width: auto;
  margin: 1% 1px 5px 1px;
  text-align: center;
}

figure img {
  border: 5px ridge var(--figure-border);
  background-color: var(--figure-bg);
  padding: 10px;
}

figcaption {
  width: 100%;
  font: bold 1rem/normal "Georgia", sans-serif;
  color: var(--text);
  text-align: center;
  background-color: var(--figure-bg);
  border: 2px dashed var(--figcaption-border);
  padding: 1%;
}

p {
  font-family: Arial, sans-serif;
  margin: 5px;
  padding: 1px;
  text-align: justify;
  text-indent: 10px;
  font-size: 1.1rem;
  line-height: 1.5rem;
}

.theme-toggle {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 10000;
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-bg);
  color: var(--heading);
  box-shadow: 0 3px 10px var(--shadow);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0;
}

.theme-toggle:hover,
.theme-toggle:focus-visible {
  background: var(--menu-bg);
  color: var(--link-hover);
  outline: 2px solid var(--accent-strong);
  outline-offset: 2px;
}
